package cn.oppexecise;

/**
 * @author SWJ
 * @create 2021-06-16 11:47
 * 测试常用包装类
 */
public class TestNumber {
    static Integer i0;

    public static void main(String[] args) {
        /**Integer类型的默认值是null*/
        System.out.println(i0);
        Integer i1 = new Integer(5);
        Integer i2 = new Integer(5);
        System.out.println(i1 == i2);
        //false ==比较是地址数值，两个地址值对比
        System.out.println(i1.equals(i2));
        //true
        Integer I3 = Integer.valueOf(127);
        Integer I4 = Integer.valueOf(127);
        System.out.println(I3 == I4);
        //true,Integer.valueOf(127)有高效对比效果

        Integer I6 = Integer.valueOf(3000);
        Integer I7 = Integer.valueOf(3000);
        System.out.println(I6 == I7);
        //false，超出范围，没有Integer高效的效果

        //测试Double包装类创建对象
        Double d1 =new Double(3.14);
        Double d2 =new Double(3.14);

        Double d3 =Double.valueOf(3.14);
        Double d4 =Double.valueOf(3.14);

        System.out.println(d1==d2);
        System.out.println(d3==d4);
        System.out.println(d2==d3);
        //都是false Double没有高效效果,只有Integer柴油
    }
}
